//
//  LoginViewController.m
//  FengyuanXS
//
//  Created by 王冬 on 2020/7/25.
//  Copyright © 2020 王冬. All rights reserved.
//

#import "LoginViewController.h"
#import "ConfirmViewController.h"
#import "RootViewController.h"
#import "TabViewController.h"
@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *phoneText;
@property (weak, nonatomic) IBOutlet UITextField *passwordText;
@property (nonatomic, assign) BOOL isCanSideBack;
@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewDidDisappear:(BOOL)animated {
    
    [super viewDidDisappear:animated];
    [self resetSideBack];
}
/**
 *恢复边缘返回
 */
- (void)resetSideBack {
    
    self.isCanSideBack = YES;
    //开启ios右滑返回
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.delegate = nil;
    }
}

- (IBAction)registerBtn:(UIButton *)sender {
    
    ConfirmViewController *configVC = [ConfirmViewController loadStroyboard:[ConfirmViewController new]];
    configVC.type = @"1";
    
    [self.navigationController pushViewController:configVC animated:YES];
    
}
- (IBAction)forgetBtn:(UIButton *)sender {
    
    ConfirmViewController *configVC = [ConfirmViewController loadStroyboard:[ConfirmViewController new]];
    configVC.type = @"0";
    
    [self.navigationController pushViewController:configVC animated:YES];
}
- (IBAction)commitBtn:(BoardButton *)sender {
    
    
    
    if (self.phoneText.text.length == 0||self.passwordText.text.length == 0) {
        [[ToastManager shardInstance]showToast:@"用户名密码不能为空"];
    }else{
        [TokenManager saveToken:self.phoneText.text];
        
        [[ToastManager shardInstance]showSystemProgress:self.view];
        [[ApiManager ShardInstance]loginAccount:self.phoneText.text password:self.passwordText.text resultBlock:^(NSDictionary *data, NSError *error) {
            BaseModel *model = [BaseModel mj_objectWithKeyValues:data];
             [[ToastManager shardInstance]hideProgress:self.view];
            if (model.code == 1) {
                UserModel *model = [UserModel mj_objectWithKeyValues:data[@"rs"]];
                [TokenManager saveUserId:model.id];
                [TokenManager saveSection_main:model.section_main];
                [TokenManager saveSection_normal:model.section_normal];
                [TokenManager saveLeader_main:model.leader_main];
                [TokenManager saveLeader_normal:model.leader_normal];
                [TokenManager saveIsheadOffice:model.is_headOffice];
                
                TabViewController *rootVC = [[TabViewController alloc]init];
                
                rootVC.modalPresentationStyle = UIModalPresentationFullScreen;
                [self presentViewController:rootVC animated:YES completion:nil];
               
            }else{
                [[ToastManager shardInstance]showToast:model.msg];
            } // 权益诉求
            
            
            
            
        }];
    }
    
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
